package com.ctshk.app.cms.controller;


import com.ctshk.common.annotations.OperationLogAnnotation;
import com.ctshk.common.dto.Result;
import com.ctshk.common.enums.OperationLogModel;
import com.ctshk.common.enums.OperationLogType;
import com.ctshk.common.model.PageResponse;
import com.ctshk.common.web.support.BaseController;
import com.ctshk.rpc.cms.dto.ContentClassificationDTO;
import com.ctshk.rpc.cms.dto.ContentClassificationListDTO;
import com.ctshk.rpc.cms.req.ContentClassificationAddReq;
import com.ctshk.rpc.cms.req.ContentClassificationQueryReq;
import com.ctshk.rpc.cms.req.ContentClassificationUpdateReq;
import com.ctshk.rpc.cms.req.UpdateStatusReq;
import com.ctshk.rpc.cms.service.IContentClassificationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 内容分类 前端控制器
 * </p>
 *
 * @author LiZhiming
 * @since 2021-04-23
 */
@Api(value = "内容分类-app",tags = "内容分类-app")
@RestController
@RequestMapping("/content-classification-app")
public class ContentClassificationController extends BaseController {
    @DubboReference
    private IContentClassificationService contentClassificationService;

    @ApiOperation(value = "新增文章分类-app", notes = "新增文章分类-app")
    @OperationLogAnnotation(operModul = OperationLogModel.CMS, operType = OperationLogType.ADD)
    @PostMapping("/add")
    public Result add(@RequestBody @Valid ContentClassificationAddReq req) {
        return contentClassificationService.add(req, getCurrentUser(getRequest()));
    }

    @ApiOperation(value = "查询文章分类作为下拉列表-app", notes = "查询文章分类作为下拉列表-app")
    @OperationLogAnnotation(operModul = OperationLogModel.CMS, operType = OperationLogType.QUERY)
    @GetMapping("/getSelectList")
    public Result<List<ContentClassificationDTO>> getSelectList() {
        return contentClassificationService.getSelectList();
    }

    @ApiOperation(value = "查询文章分类列表-app", notes = "查询文章分类列表-app")
    @OperationLogAnnotation(operModul = OperationLogModel.CMS, operType = OperationLogType.QUERY)
    @PostMapping("/getList")
    public PageResponse<ContentClassificationListDTO> getList(@RequestBody @Valid ContentClassificationQueryReq req) {
        return contentClassificationService.getList(req);
    }

    @ApiOperation(value = "查询文章分类子分类-app", notes = "查询文章分类子分类-app")
    @OperationLogAnnotation(operModul = OperationLogModel.CMS, operType = OperationLogType.QUERY)
    @GetMapping("/getListChild/{patentId}")
    public Result<ContentClassificationDTO> getChild(@PathVariable("patentId") Long patentId) {
        return contentClassificationService.getChild(patentId);
    }

    @ApiOperation(value = "查询文章分类-app", notes = "查询文章分类-app")
    @OperationLogAnnotation(operModul = OperationLogModel.CMS, operType = OperationLogType.QUERY)
    @GetMapping("/getContentClassificationById/{id}")
    public Result<ContentClassificationListDTO> getContentClassificationById(@PathVariable("id") Long id) {
        return contentClassificationService.getContentClassificationById(id);
    }

    @ApiOperation(value = "查询文章分类-app", notes = "查询文章分类-app")
    @OperationLogAnnotation(operModul = OperationLogModel.CMS, operType = OperationLogType.QUERY)
    @GetMapping("/getContentClassificationByCode/{code}")
    public Result<ContentClassificationListDTO> getContentClassificationByCode(@PathVariable("code") String code) {
        return contentClassificationService.getContentClassificationByCode(code);
    }

    @ApiOperation(value = "修改文章分类-app", notes = "修改文章分类-app")
    @OperationLogAnnotation(operModul = OperationLogModel.CMS, operType = OperationLogType.UPDATE)
    @PostMapping("/update")
    public Result update(@RequestBody @Valid ContentClassificationUpdateReq req) {
        return contentClassificationService.update(req,getCurrentUser(getRequest()));
    }

    @ApiOperation(value = "修改有效状态-app", notes = "修改有效状态-app")
    @OperationLogAnnotation(operModul = OperationLogModel.CMS, operType = OperationLogType.UPDATE)
    @PostMapping("/updateStatusById")
    public Result updateStatusById(@RequestBody @Valid UpdateStatusReq req) {
        return contentClassificationService.updateStatusById(req);
    }
}
